﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace GMusicBox.Core
{
    public sealed class Album
    {
        public Album()
        {
            Artist = new Artist();
            Id = "";
            Name = "";
            Song = new Song[0];
            ThumbnailLink = "";
        }

        public Album(string id, string name) : this()
        {
            Id = id;
            Name = name;
        }

        public Artist Artist { get; internal set; }

        public string Id { get; set; }

        public string Name { get; internal set; }

        public Song[] Song { get; internal set; }

        public string ThumbnailLink { get; internal set; }

        public void GetAlbumData()
        {
            try
            {
                if (Id == "") throw new ArgumentNullException("专辑Id未指定，请先设置Id属性，再执行 GetAlbumData 函数。");
                XmlDocument xd = new XmlDocument(); xd.Load("http://www.google.cn/music/album?id=" + Id + "&output=xml");
                XmlNodeList xn = xd.SelectNodes("results/playlist/info");
                foreach (XmlNode x in xn)
                {
                    Artist = new Artist(x.SelectSingleNode("artistId").InnerText, x.SelectSingleNode("artist").InnerText);
                    Name = x.SelectSingleNode("name").InnerText;
                    ThumbnailLink = x.SelectSingleNode("thumbnailLink").InnerText;
                }
                Song = GMusicBox.Core.Song.GetSongList(xd, "results/playlist/songList/song");
            }
            catch { }
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
